import { defineStore } from 'pinia'
import { store } from '/@/store'
import type { AxiosResponse } from 'axios'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'

import roleService from '/@/api/cn/core/sign/roleService'

import type { Role } from '/@/model/cn/core/sign/eo/Role'
import type { RoleQO } from '/@/model/cn/core/sign/qo/RoleQO'
import type { RoleVO } from '/@/model/cn/core/sign/vo/RoleVO'

import type { RoleAO } from '/@/model/cn/core/sign/ao/RoleAO'

import type { AuthList } from '/@/model/cn/core/sign/eo/AuthList'

import type { RoleMenuTreeVO } from '/@/model/cn/core/sign/vo/RoleMenuTreeVO'

interface RoleState {
}

export const useRoleStore = defineStore({
  id: 'role',
  state: (): RoleState => ({
  }),
  getters: {
  },
  actions: {
    save(param: Param<Role>): Promise<Res<Role>> {
      return new Promise<Res<Role>>((resolve, reject) => {
        roleService.save(param).then((res: AxiosResponse<Res<Role>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    saveBatch(param: Param<Role>): Promise<Res<Role>> {
      return new Promise<Res<Role>>((resolve, reject) => {
        roleService.saveBatch(param).then((res: AxiosResponse<Res<Role>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    update(param: Param<Role>): Promise<Res<Role>> {
      return new Promise<Res<Role>>((resolve, reject) => {
        roleService.update(param).then((res: AxiosResponse<Res<Role>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    updateBatch(param: Param<Role>): Promise<Res<Role>> {
      return new Promise<Res<Role>>((resolve, reject) => {
        roleService.updateBatch(param).then((res: AxiosResponse<Res<Role>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    remove(param: Param<Role>): Promise<Res<Role>> {
      return new Promise<Res<Role>>((resolve, reject) => {
        roleService.remove(param).then((res: AxiosResponse<Res<Role>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    removeBatch(param: Param<Role>): Promise<Res<Role>> {
      return new Promise<Res<Role>>((resolve, reject) => {
        roleService.removeBatch(param).then((res: AxiosResponse<Res<Role>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    count(param: Param<RoleQO>): Promise<Res<Role>> {
      return new Promise<Res<Role>>((resolve, reject) => {
        roleService.count(param).then((res: AxiosResponse<Res<Role>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pk(param: Param<RoleQO>): Promise<Res<Role>> {
      return new Promise<Res<Role>>((resolve, reject) => {
        roleService.pk(param).then((res: AxiosResponse<Res<Role>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    query(param: Param<RoleQO>): Promise<Res<Role>> {
      return new Promise<Res<Role>>((resolve, reject) => {
        roleService.query(param).then((res: AxiosResponse<Res<Role>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    paging(param: Param<RoleQO>): Promise<Res<Role>> {
      return new Promise<Res<Role>>((resolve, reject) => {
        roleService.paging(param).then((res: AxiosResponse<Res<Role>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    countVo(param: Param<RoleQO>): Promise<Res<RoleVO>> {
      return new Promise<Res<RoleVO>>((resolve, reject) => {
        roleService.countVo(param).then((res: AxiosResponse<Res<RoleVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pkVo(param: Param<RoleQO>): Promise<Res<RoleVO>> {
      return new Promise<Res<RoleVO>>((resolve, reject) => {
        roleService.pkVo(param).then((res: AxiosResponse<Res<RoleVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    queryVo(param: Param<RoleQO>): Promise<Res<RoleVO>> {
      return new Promise<Res<RoleVO>>((resolve, reject) => {
        roleService.queryVo(param).then((res: AxiosResponse<Res<RoleVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pagingVo(param: Param<RoleQO>): Promise<Res<RoleVO>> {
      return new Promise<Res<RoleVO>>((resolve, reject) => {
        roleService.pagingVo(param).then((res: AxiosResponse<Res<RoleVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    getAuthListByRoleIdLoginSide(param: Param<RoleAO>): Promise<Res<string>> {
      return new Promise<Res<string>>((resolve, reject) => {
        roleService.getAuthListByRoleIdLoginSide(param).then((res: AxiosResponse<Res<string>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    saveAuthList(param: Param<RoleAO>): Promise<Res<AuthList>> {
      return new Promise<Res<AuthList>>((resolve, reject) => {
        roleService.saveAuthList(param).then((res: AxiosResponse<Res<AuthList>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    getRoleMenuTreeByRoleIdLoginSide(param: Param<RoleAO>): Promise<Res<RoleMenuTreeVO>> {
      return new Promise<Res<RoleMenuTreeVO>>((resolve, reject) => {
        roleService.getRoleMenuTreeByRoleIdLoginSide(param).then((res: AxiosResponse<Res<RoleMenuTreeVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
  },
})

export function useRoleStoreWithout() {
  return useRoleStore(store)
}
